#ifndef SHOPPINGCART_UI_LOGIC_H
#define SHOPPINGCART_UI_LOGIC_H

#include <QMap>
#include <QObject>
#include<QComboBox>
#include "shoppingcart_ui.h"

/*class ShoppingCartLogic : public QObject
{
    Q_OBJECT

public:
    static ShoppingCartLogic *getInstance()
    {
        static ShoppingCartLogic instance;
        return &instance;
    }
    explicit ShoppingCartLogic(ShoppingCartUI *ui, QObject *parent = nullptr);
    ~ShoppingCartLogic();

private:
    int selectedAddressId = -1;
    ShoppingCartUI *ui; // Pointer to the UI
      void onAddressSelected(int addressId, const QJsonArray &productIds);
    void setupProductData(); // Setup products in the shopping cart
    PptpClient pptpclient;
    PptpMessage requestMessage;


private slots:
    void onRemoveButtonClicked(int row);

public slots:
    void addProductRow(const QPixmap &image, const QString &name, const QString &price, int productId, int quantity);
    void onBuyResponse(PptpMessage responseMessage);
    void onAddressResponse(PptpMessage responseMessage);
    void onCheckoutButtonClicked();

signals:
    void refreshorder();
};*/

class ShoppingCartLogic : public QObject
{
    Q_OBJECT
    Q_DISABLE_COPY(ShoppingCartLogic)

public:
    static ShoppingCartLogic *getInstance();
    ~ShoppingCartLogic();
    static  void resetInstance();
    void addProductRow(const QPixmap &image, const QString &name, const QString &price, int productId, int quantity);
    void onBuyResponse(PptpMessage responseMessage);
    void onAddressResponse(PptpMessage responseMessage);
    void onCheckoutButtonClicked();
     static ShoppingCartLogic* instance;
signals:
    void refreshOrder();

private:

    ShoppingCartLogic(QObject *parent = nullptr);
    int selectedAddressId = -1;
    ShoppingCartUI *ui; // Pointer to the UI
    void onAddressSelected(int addressId, const QJsonArray &productIds);
    void setupProductData(); // Setup products in the shopping cart
    PptpClient pptpclient;
    PptpMessage requestMessage;
    void clearPurchasedItems();

private slots:
   //void onRemoveButtonClicked(int row);
    void onRemoveButtonClicked(QWidget *productWidget);
};



#endif // SHOPPINGCART_UI_LOGIC_H
